/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dota2patcher;

import java.io.File;
import java.util.ArrayList;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author maz
 */
public class Dota2Patcher{
    
    String processBoobies(){
        return "boobies";
    }
    
    ArrayList<String> getHelp() {
        ArrayList<String> help = new ArrayList<String>();   
        help.add("**************************************************");
        help.add("*****************Dota2Patcher v0.2******************");
        help.add("*********************************************~maz");
        help.add("");
        help.add("Directions:");
        help.add("The paths should auto generate if you have the files in the nomral "
                + "spot. If not just browes or insert the path and hit enter.");
        help.add("To patch files select the files in the directory tree to your left. "
                + "Click 'patch' and IF the files are found in the VPK they will be "
                + "Backed up with ext '.orig' at the same location and then removed "
                + "from the vpk. Removing from the VPK forces dota2 to look at the "
                + "folders for the files.");
        help.add("The program will keep track of what you have patched. Saving to a tmp "
                + "file(d2pTreePaths) on every patch run. If you want to remove a file "
                + "by unchecking it the app will auto rebuild the VPK.");
        help.add("");
        help.add("ONLY FORCE PATCH RIGHT AFTER A DOTA2 UPDATE. This will overwrite your "
                + "backup with the fresh dota2 one.. see help bellow if you f'ed yoruself.");
        help.add("");
        help.add("Help:");
        help.add("Its pretty dummy proof but if you hit force patch and messed with your "
                + "original then just validate your dota2 files and hit force patch "
                + "the first time. From there you should be set.");
        help.add("If the program is acting up you can click 'debug' which will "
                + "redirect consol output into this screen.");
        help.add("If you find a bug please submit an issue at the repo bellow.");
        help.add("");
        help.add("Repo: https://code.google.com/p/dota2patcher/");
        
        return help;
    }
    
    String dota2Path(){
        String path = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\dota 2 beta\\dota";
        File f =new File(path);
        if (f.isDirectory()) {
            return path;
        }
        path = "C:\\Program Files\\Steam\\steamapps\\common\\dota 2 beta\\dota";
        f =new File(path);
        if (f.isDirectory()) {
            return path;
        }
        return "Please enter the dota/ path and hit enter";
    }
    
    String vpkPath(){
        String path = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\dota 2 beta\\dota\\pak01_dir.vpk";
        File f =new File(path);
        if (f.isFile()) {
            return path;
        }
        path = "C:\\Program Files\\Steam\\steamapps\\common\\dota 2 beta\\dota\\pak01_dir.vpk";
        f =new File(path);
        if (f.isFile()) {
            return path;
        }
        return "Please enter the dota/pak01_dir.vpk and hit enter";
    }
    
    String cleanPath(String path) {
        if (path.substring(0,1).equals("/") || path.substring(0,1).equals("\\")) {
            path = path.substring(1);
        }
        path = path.replaceAll("\\\\", "/");
        return path;
    }
    
    void saveObject(Object objectToSave, String path) {
        try {
            FileOutputStream saveFile = new FileOutputStream(path);
            ObjectOutputStream save = new ObjectOutputStream(saveFile); 
            save.writeObject(objectToSave);
            save.close();
        } catch (IOException ex) {
            Logger.getLogger(Dota2Patcher.class.getName()).log(Level.SEVERE, null, ex);
  
        }
    }
    
    Object readObject(String path) {
        try {
            FileInputStream saveFile = new FileInputStream(path);
            ObjectInputStream restore = new ObjectInputStream(saveFile);
            Object obj = restore.readObject();
            restore.close();
            return obj;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Dota2Patcher.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Dota2Patcher.class.getName()).log(Level.SEVERE, null, ex);
  
        }
        return null;
    }
}
